﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Should;

namespace NGeo.Yahoo.PlaceFinder
{
    [TestClass]
    public class RequestTests
    {
        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void Yahoo_PlaceFinder_Request_ShouldThrowException_WhenStartIsGreaterThan99()
        {
            new Request
            {
                Start = 100,
            };
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void Yahoo_PlaceFinder_Request_ShouldThrowException_WhenStartLessThanZero()
        {
            new Request
            {
                Start = -1,
            };
        }

        [TestMethod]
        public void Yahoo_PlaceFinder_Request_ShouldPreserveStart()
        {
            var request = new Request
            {
                Start = 9,
            };
            request.Start.ShouldEqual(9);
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void Yahoo_PlaceFinder_Request_ShouldThrowException_WhenCountIsGreaterThan100()
        {
            new Request
            {
                Count = 101,
            };
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void Yahoo_PlaceFinder_Request_ShouldThrowException_WhenCountIsLessThanZero()
        {
            new Request
            {
                Count = -1,
            };
        }

        [TestMethod]
        public void Yahoo_PlaceFinder_Request_ShouldPreserveCount()
        {
            var request = new Request
            {
                Count = 5,
            };
            request.Count.ShouldEqual(5);
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void Yahoo_PlaceFinder_Request_ShouldThrowException_WhenOffsetMetersIsGreaterThan100()
        {
            new Request
            {
                OffsetMeters = 101,
            };
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void Yahoo_PlaceFinder_Request_ShouldThrowException_WhenOffsetMetersIsLessThanZero()
        {
            new Request
            {
                OffsetMeters = -1,
            };
        }

        [TestMethod]
        public void Yahoo_PlaceFinder_Request_ShouldPreserveOffsetMeters()
        {
            var request = new Request
            {
                OffsetMeters = 50,
            };
            request.OffsetMeters.ShouldEqual(50);
        }

        [TestMethod]
        public void Yahoo_PlaceFinder_Request_ShouldPreserveFlags()
        {
            var request = new Request();
            request.Flags.Add(RequestFlag.Airport);
            request.Flags.ShouldContain(RequestFlag.Airport);
        }

        [TestMethod]
        public void Yahoo_PlaceFinder_Request_ShouldSerializeFlags()
        {
            var request = new Request();
            request.Flags.Add(RequestFlag.Airport);
            request.Flags.Add(RequestFlag.TelephoneAreaCode);
            var flags = request.GetFlagsAsString();
            flags.ShouldEqual("QR");
        }

        [TestMethod]
        public void Yahoo_PlaceFinder_Request_ShouldPreserveGFlags()
        {
            var request = new Request();
            request.GFlags.Add(RequestGFlag.QuickMode);
            request.GFlags.ShouldContain(RequestGFlag.QuickMode);
        }

        [TestMethod]
        public void Yahoo_PlaceFinder_Request_ShouldSerializeGFlags()
        {
            var request = new Request();
            request.GFlags.Add(RequestGFlag.QuickMode);
            request.GFlags.Add(RequestGFlag.LimitToLocaleCountry);
            var flags = request.GetGFlagsAsString();
            flags.ShouldEqual("QL");
        }

    }
}
